Fix typescript-ts-mode indentation (bug#77803)
authorKonstantin Kharlamov <Hi-Angel@yandex.ru>
Tue, 15 Apr 2025 14:34:11 +0000 (17:34 +0300)
committerYuan Fu <casouri@gmail.com>
Fri, 18 Apr 2025 23:40:06 +0000 (16:40 -0700)
Don't align variable names to their declaratory expression.

Before this commit in code like:

    const a = 1,
          b = 2;

the b would get indented to `const'.  Similarly for `var' and
`let'. The expected behavior instead is getting indented to
`typescript-ts-mode-indent-offset'.

* lisp/progmodes/typescript-ts-mode.el
(typescript-ts-mode--indent-rules): Indent identifiers declarations to
`typescript-ts-mode-indent-offset'.
* test/lisp/progmodes/typescript-ts-mode-resources/indent.erts
(Lexical and variable declarations): Update test accordingly.

lisp/progmodes/typescript-ts-mode.el
test/lisp/progmodes/typescript-ts-mode-resources/indent.erts

index b4b078950c3bfd6cb5fa8b9c72ada3c3a1d1f431..f1410df642131e65d6f85428d6defd03f4857512 100644 (file)
@@ -130,7 +130,7 @@ Argument LANGUAGE is either `typescript' or `tsx'."
      ((parent-is "type_arguments") parent-bol typescript-ts-mode-indent-offset)
      ((parent-is "type_parameters") parent-bol typescript-ts-mode-indent-offset)
      ((parent-is ,(rx (or "variable" "lexical") "_" (or "declaration" "declarator")))
-      typescript-ts-mode--anchor-decl 1)
+      parent-bol typescript-ts-mode-indent-offset)
      ((parent-is "arguments") parent-bol typescript-ts-mode-indent-offset)
      ((parent-is "array") parent-bol typescript-ts-mode-indent-offset)
      ((parent-is "formal_parameters") parent-bol typescript-ts-mode-indent-offset)
index 877382953c13a7367787339605ddbe67596df3fd..ef7368602d6b96111e78b4b9f2e8f9019222e9ad 100644 (file)
@@ -67,22 +67,22 @@ Name: Lexical and variable declarations
 =-=
 const foo = () => {
   let x = 1,
-      yyyy: {
-        [k: string | number]: string,
-      } = {
-        "foo": "foo",
-        "bar": "bar",
-      };
+    yyyy: {
+      [k: string | number]: string,
+    } = {
+      "foo": "foo",
+      "bar": "bar",
+    };
   var obar = 1,
-      fo: { [x: any]: any } = {
-        "a": 1,
-        "b": 2,
-      };
+    fo: { [x: any]: any } = {
+      "a": 1,
+      "b": 2,
+    };
   const cccc = 1,
-        bbb = {
-          "x": 0
-        },
-        ddddd = 0;
+    bbb = {
+      "x": 0
+    },
+    ddddd = 0;
   // First decls with value starting on same line
   const a = (x: string): string => {
     return x + x;